package com.smxy.mall.controller;

import com.smxy.mall.common.Response;
import com.smxy.mall.model.request.RoleReq;
import com.smxy.mall.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "权限管理")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    @ApiOperation("新增/编辑 角色")
    @PostMapping("/save")
    public Object save(@Valid RoleReq roleReq) {
        return Response.success(roleService.save(roleReq));
    }

    @ApiOperation("角色列表")
    @GetMapping("/list")
    public Object list() {
        return Response.success(roleService.list());
    }

    @ApiOperation("改变角色状态")
    @PostMapping("/changeStatus")
    public Object changeStatus(@RequestParam("status") Integer status,@RequestParam("id") Integer id) {
        return Response.success(roleService.changeStatus(status,id));
    }

    @ApiOperation("角色详情")
    @GetMapping("/roleInfo")
    public Object roleInfo(@RequestParam("id")Integer id){
        return Response.success(roleService.roleInfo(id));
    }
}
